2 Problem: 10004 - Bicoloring (UVa online judge)
4 Author: Andrés Mejía-Posada (http://github.com/andmej/acm)
5 Algorithm: Depth-first search
12 bool dfs(int u
, int c
, int * color
, vector
<int> * g
){
13 //printf("u = %d, c = %d, color[%d] = %d\n", u, c, u, color[u]);
14 if (color
[u
] != 0) return (c
== color
[u
]);
17 for (int i
=0; i
<g
[u
].size(); ++i
){
18 int nc
= (c
== 1 ? 2 : 1);
19 if (dfs(g
[u
][i
], nc
, color
, g
) == false){
28 while (cin
>> n
&& n
){
32 memset(color
, 0, sizeof color
);
41 cout
<< (dfs(0, 1, color
, g
) ? "" : "NOT ") << "BICOLORABLE." << endl
;